import { ElMessage } from 'element-plus'
import 'element-plus/es/components/message/style/css'
import { TABLE_ACCOUNT_CONFIGS } from '@/components/EnergyDataReport/config'

export interface List {
  id: number
  name: string
  description: string
  [key: string]: any
}

// TODO
function request(): Promise<List[]> {
  return new Promise((resolve) => {
    setTimeout(() => {
      const data = Object.keys(TABLE_ACCOUNT_CONFIGS).map((key) => {
        const target = TABLE_ACCOUNT_CONFIGS[key as keyof typeof TABLE_ACCOUNT_CONFIGS]
        return {
          id: target.ID,
          name: target.NAME,
          description: '说明：\n1、xxxx\n2、yyyyy',
        }
      })
      resolve(data)
    }, 200)
  })
}

function save() {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({})
    }, 200)
  })
}

export default function useLists() {
  const lists = ref<List[]>([])

  async function queryLists() {
    const data = await request()
    lists.value = data
  }

  async function clickSave() {
    await save()
    ElMessage.success('保存成功')
  }

  return {
    lists,
    queryLists,
    clickSave,
  }
}
